<?php

class Role extends CActiveRecord {
        const ROLE_ADMIN=1;
    
        public function rules(){
		return array(
			array('name', 'required', 'on'=>'create, update'),
                        array('name', 'unique', 'on'=>'create, update'),
                        array('id, name', 'safe', 'on'=>'search')
		);
	}
    
        public static function model($className=__CLASS__){
            return parent::model($className);
        }

        public function tableName(){
            return 'roles';
        }
        
        
        public function search(){
                $criteria=new CDbCriteria();
                if($this->id){
                        $criteria->addCondition('id='.$this->id);
                }
                
                if($this->name){
                        $criteria->addCondition('name LIKE "%'.$this->name.'%"');
                }
            
                return new CActiveDataProvider('Role', array(
                        'criteria'=>$criteria
                ));
        }
}

?>
